package t.com.util;

import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * 项目名称：三农
 * 类描述：网络的加载工具
 * 创建人：zcx
 * 创建时间：2017-09-05
 * 修改人：暂无
 * 修改时间：暂无
 * 修改备注：暂无
 */

@SuppressWarnings("ALL")
public class HttpUtil {
    //请求体RequestBody
    private static RequestBody body;
    private static OkHttpClient client = null;
    private HttpUtil() {}
    //单例模式获取OkHttpClient的实例。
    public static OkHttpClient getInstance() {
        if (client == null) {
            synchronized (HttpUtil.class) {
                if (client == null)
                    client = new OkHttpClient();
            }
        }
        return client;
    }
    //Okhttp3--Post请求
    public static void sendOkHttpPostRequest(final String address, final okhttp3.Callback callback){
        LogUtil.d("aaaa",address);
        Request request = new Request.Builder()
                .url(address)
                .post(RequestBody.create(null,""))
                .build();
        getInstance().newCall(request).enqueue(callback);
    }

    //Okhttp3--Get请求
    public static void sendOkHttpGetRequest(final String address, final okhttp3.Callback callback) {
        Request request = new Request.Builder()
                .url(address)
                .build();
        getInstance().newCall(request).enqueue(callback);
    }

}
